package com.ruoyi.web.controller.ring;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.dict.SysNormalDisable;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ring.domain.HealthQuestion;
import com.ruoyi.ring.service.IHealthQuestionService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 健康问卷Controller
 * 
 * @author liuwp
 * @date 2025-07-29
 */
@RestController
@RequestMapping("/ring/health_question")
public class HealthQuestionController extends BaseController
{
    @Resource
    private IHealthQuestionService healthQuestionService;

    /**
     * 查询健康问卷列表
     */
    @PreAuthorize("@ss.hasPermi('ring:health_question:list')")
    @GetMapping("/list")
    public TableDataInfo list(HealthQuestion healthQuestion)
    {
        startPage();
        List<HealthQuestion> list = healthQuestionService.selectHealthQuestionList(healthQuestion);
        return getDataTable(list);
    }

    /**
     * 导出健康问卷列表
     */
    @PreAuthorize("@ss.hasPermi('ring:health_question:export')")
    @Log(title = "健康问卷", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HealthQuestion healthQuestion)
    {
        List<HealthQuestion> list = healthQuestionService.selectHealthQuestionList(healthQuestion);
        ExcelUtil<HealthQuestion> util = new ExcelUtil<HealthQuestion>(HealthQuestion.class);
        util.exportExcel(response, list, "健康问卷数据");
    }

    /**
     * 获取健康问卷详细信息
     */
    @PreAuthorize("@ss.hasPermi('ring:health_question:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(healthQuestionService.selectHealthQuestionById(id));
    }

    /**
     * 新增健康问卷
     */
    @PreAuthorize("@ss.hasPermi('ring:health_question:add')")
    @Log(title = "健康问卷", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HealthQuestion healthQuestion)
    {
        return toAjax(healthQuestionService.insertHealthQuestion(healthQuestion));
    }

    /**
     * 修改健康问卷
     */
    @PreAuthorize("@ss.hasPermi('ring:health_question:edit')")
    @Log(title = "健康问卷", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HealthQuestion healthQuestion)
    {
        return toAjax(healthQuestionService.updateHealthQuestion(healthQuestion));
    }

    /**
     * 删除健康问卷
     */
    @PreAuthorize("@ss.hasPermi('ring:health_question:remove')")
    @Log(title = "健康问卷", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(healthQuestionService.deleteHealthQuestionByIds(ids));
    }


    @PreAuthorize("@ss.hasPermi('ring:health_question:list')")
    @GetMapping("/query")
    public AjaxResult query(HealthQuestion healthQuestion)
    {
        healthQuestion.setStatus(SysNormalDisable.NORMAL.getValue());
        PageHelper.orderBy("order_by desc");
        List<HealthQuestion> list = healthQuestionService.selectHealthQuestionList(healthQuestion);
        return AjaxResult.success(list);
    }

}
